/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare');
(function () {
	
	/**
	 * Display a vehicle with a customizable view
	 * @class VehiclePanel
	 * @extends Ext.BoxComponent
	 * @namespace net.autodata.compare
	 */
	var Panel = Ext.extend(Ext.BoxComponent, {
		
		autoEl: {
			tag: 'div',
			cls: 'vehicle-panel'
		},
		
		/**
		 * @property vehicle
		 * @type Object
		 */
		vehicle: undefined,
		
		/**
		 * @property view
		 * @type Object
		 */
		view: undefined,
		
		constructor: function ()
		{
			this.addEvents({'datachanged': true });
			Panel.superclass.constructor.apply(this, arguments);
		},
		
		initComponent: function ()
		{
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();
			view.init(this);
			this.relayEvents(view, ['change', 'remove']);
		},
		
		/**
		 * @method getView
		 */
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.CompetitorVehicleView(this.viewCfg);
			}
			
			return this.view;
		},
		
		/**
		 * @method setVehicle
		 * @param {Object} vehicle
		 */
		setVehicle: function (vehicle)
		{
			this.vehicle = vehicle;
			this.fireEvent('datachanged', vehicle);
		},
		
		/**
		 * @method getVehicle
		 * @returns Object
		 */
		getVehicle: function ()
		{
			return this.vehicle;
		},
		
		/**
		 * @method onRender
		 * @private
		 */
		onRender: function ()
		{
			Panel.superclass.onRender.apply(this, arguments);			
			var view = this.getView();
			view.render();
		}
	});
	
	net.autodata.compare.VehiclePanel = Panel;	
})();
